// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import VueRouter from 'vue-router'
import VueResource from 'vue-resource'

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'

import App from './App'
// import Nav from './components/Leftnav.vue'
import routes from './routes'
import store from './vuex/store'

Vue.use(VueResource)
Vue.use(VueRouter)
Vue.use(ElementUI)

const router = new VueRouter({
  routes
})

router.beforeEach(function (to, from, next) {
  if (to.path === '/login') {
    next()
  }
  if (!sessionStorage.getItem('accessToken')) {  // FIXME: 后端验证
    next({
      path: '/login'
    })
  } else {
    next()
  }
})

// const BACKEND_URL = 'http://localhost:8000'
// const SPIDER_URL = 'http://localhost:6800'
/* eslint-disable no-new */
// 实例化我们的Vue
new Vue({
  el: '#app',
  router,
  // BACKEND_URL,
  // SPIDER_URL,
  store,
  ...App
})
